﻿// <copyright file="PermittedIPMask.cs" company="SharpSTS">
// Copyright (c) 2007, 2008 All Right Reserved, http://sharpsts.com/
//
// This source is subject to the Microsoft Permissive License.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Barry Dorrans</author>
// <email>barryd@idunno.org</email>
// <date>2008-06-10</date>
// <summary>Represents a network address and netmask used in the configuration file.</summary>

namespace SharpSTS.CardControl.Configuration
{
    using System.Configuration;

    /// <summary>
    /// Represents an IP Mask allowed to call the card control service
    /// </summary>
    public sealed class PermittedIPMask : ConfigurationElement
    {
        /// <summary>
        /// The key for the configuration element for this class.
        /// </summary>        
        private const string IpMaskConfigurationKey = @"ipMask";

        /// <summary>
        /// Initializes a new instance of the <see cref="PermittedIPMask"/> class.
        /// </summary>
        public PermittedIPMask()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="PermittedIPMask"/> class.
        /// </summary>
        /// <param name="ipMask">The IP address.</param>
        public PermittedIPMask(string ipMask)
            : this()
        {
            this.IPMask = ipMask;            
        }

        /// <summary>
        /// Gets or sets the allowed IP network address and subnext mask.
        /// </summary>
        [ConfigurationProperty(IpMaskConfigurationKey, DefaultValue = "127.0.0.1/255.255.255.255", IsKey = true, IsRequired = true)]
        public string IPMask
        {
            get
            {
                return ((string)(base[IpMaskConfigurationKey]));
            }

            set
            {
                base[IpMaskConfigurationKey] = value;
            }
        }
    }
}
